// pages/home/index.js
//获取应用实例  
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
  },
  openBluetoothAdapter:function(){
    wx.openBluetoothAdapter({
      success: function (res) {
        console.log(res)
      }
    })
  },
  getBluetoothAdapterState:function(){
    wx.getBluetoothAdapterState({
      success: function (res) {
        console.log(res)
      }
    })
  }, 
  startBluetoothDevicesDiscovery:function(){
    wx.startBluetoothDevicesDiscovery({
      services: [],
      success: function (res) {
        console.log(res)
      }
    })
  },
  //监听蓝牙适配器状态变化事件
  onBluetoothAdapterStateChange: function () {
    wx.onBluetoothAdapterStateChange(function (res) {
      console.log(`adapterState changed, now is`, res)
    })
  },  
  //获取所有已发现的蓝牙设备  
  getBluetoothDevices: function () {
    var that = this;
    wx.getBluetoothDevices({
      success: function (res) {
        console.log(res)               
        that.setData({
          'list': res.devices
        });
        
      },
    })
  }, 
  //连接低功耗蓝牙设备  
  createBLEConnection: function () {
    wx.createBLEConnection({
      deviceId: '74:F0:7D:C9:CB:4F',
      success: function (res) {
        // success  
        console.log(res)
      },
      fail: function (res) {
        // fail  
      },
      complete: function (res) {
        // complete  
      }
    })
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})